<script type="text/javascript" src="<?php echo base_url('public/plupload/js/plupload.full.min.js'); ?>" ></script>
<script type="text/javascript" src="<?php echo base_url('public/plupload/js/jquery.plupload.queue/jquery.plupload.queue.min.js'); ?>" ></script>
<script type="text/javascript" src="<?php echo base_url('public/plupload/js/i18n/zh_CN.js'); ?>" ></script>
<link rel="stylesheet" href="<?php echo base_url('public/plupload/js/jquery.plupload.queue/css/jquery.plupload.queue.css'); ?>" />

<div class="search-wrap">
    <div class="search-content">
        <table class="search-tab" id="goods_menu">
        </table>

        <div class="search-tab layer-photos-demo" id="layer-photos-demo">
        <?php foreach($list as $k => $v): ?>
            <div style="margin: 20px 0px 20px 20px;float: left">
            <img src="<?=$v['path'].$v['thumb']?>" width="150px" height="150px"  layer-pid="<?=$v['id']?>" layer-src="<?=$v['path'].$v['file_name']?>" alt="<?=$v['name']?>">
            <br />
            <a href="javascript:;" onclick="img_delete(<?=$v['id']?>)">删除</a> | 
            <a href="javascript:;" onclick="set_sort(<?=$v['id']?>,<?=$v['sort']?>)">排序<?=$v['sort'] == 0 ? '' : '【'.$v['sort'].'】'?></a>
            </div>
        <?php endforeach;?>
        </div>

        <div class="result-wrap">
            <div class="result-content">
                <form action="http://up.qiniu.com/" method="post" id="myform" name="myform" enctype="multipart/form-data">
                    <table class="insert-tab" width="100%">
                        <tbody>
                            
                            <tr>
                                <th><i class="require-red">*</i>上传：</th>
                                <td>
                                    <input name="file" id="" type="file">
                                    <span>最多只能上传7张图片</span>
                                </td>
                            </tr>
                            <tr>
                                <th><i class="require-red">*</i>备注：</th>
                                <td>
                                    <input class="common-text required" id="title" name="title" size="50" value="" type="text">
                                </td>
                            </tr>
                            <tr>
                                <th></th>
                                <td>
                                    <input type="hidden" name="gid" value="<?=$res['id']?>">
                                    <input name="key" type="hidden" value="123456.jpg">
                                     <input name="token" type="hidden" value="<?php echo $upToken;?>">
                                     
                                    <input class="btn btn-primary btn6 mr10" value="提交" type="submit">
                                    <input class="btn btn6" onclick="history.go(-1)" value="返回" type="button">
                                </td>
                            </tr>
                        </tbody></table>
                </form>
            </div>
        </div>
    </div>
</div>


<script type="text/javascript">
//ajax提交
$('#myform').submit(function() {
    $(this).ajaxSubmit(function(data){
        if(data == 1){
             location.reload();
        }else{
            layer.alert(data,{
                icon:2,
            });
        }
    })
    return false;
})

$(function() {
    var photos = Array(); // 用于存放照片信息
    // 设置参数，初始化Plupload

    $("#muilti_uploader").pluploadQueue({

        runtimes : 'html5,silverlight,html4',

        url : "http://up.qiniu.com/",

        chunk_size : '512kb',

        rename : true,

        dragdrop: true,

        filters : {

            max_file_size : '1mb',

            mime_types: [

                {title : "Image files", extensions : "jpg,jpeg,gif,png"},

                //{title : "Zip files", extensions : "zip"}

            ]

        },

        multipart: true,

        multipart_params: {

            'token': '<?php echo $upToken;?>', //token，需要从服务器获取

        },

        flash_swf_url : '<?php echo base_url("public/plupload/js/Moxie.swf"); ?>'

    });

 

    var uploader = $('#muilti_uploader').pluploadQueue();

    //上传文件之前触发

    uploader.bind('BeforeUpload', function(uploader, file){

        var file_ext = file.name.substr(file.name.lastIndexOf(".")); // 图片后缀

        //指定文件的名称，如果不设置，七牛会默认将文件的hash值作为文件的名字

        uploader.settings.multipart_params.key = parseInt(new Date().valueOf()/1000) + '-' + parseInt(Math.random()*8999 + 1000) +file_ext;

    });

    //成功上传一个文件后触发

    uploader.bind('FileUploaded', function(uploader, file, responseObject) {

        //将七牛返回的json数据转换成对象

        var res = eval('('+responseObject.response+')'); 

        var a = JSON.stringify(res, undefined, 2);

        alert(a);

        // //组合文件信息

        // var photo = new Object();

        // //因为在数据库中，我用字段名name来存储文件名，用path来存储七牛上的文件名

        // //所以这里的photo对象属性为name和path，如果你用的字段名和我的不一样，请自行修改

        // photo.name = file.name; // 上传之前的图片名称

        // photo.path = res.key; // 保存后的图片名称(含前缀)

        // photos.push(photo); //将对象压入到photos数组

 

    });

    //全部文件上传完成后触发

    uploader.bind('UploadComplete', function(uploader, file){

        //文件全部成功上传后，将数据传递给CI框架进行处理

        // $.ajax({

        //     url: "<?php echo site_url('photo/save'); ?>", //ci框架处理地址

        //     type: "POST",

        //     data: {files:JSON.stringify(photos)},

        //     success: function(msg){

        //         alert(msg);

        //     }

        // });

    });

});

</script>